# Resource module provides several class and instance methods,
# which can be included by class which should have resource behavior.

module PNEngine
  module Resource
    module InstanceMethods
      def url
        res_type = self.class.to_s.split("::").last.downcase
        res_type = "place" if res_type == "pullplace" || res_type == "pushplace"
        (Merb::Config[:root] + "/#{res_type}/#{id}").to_s
      end
      
      def log_name
        "#{self.class.to_s.split("::").last}##{self.id}##{self.pid if self.respond_to?(:pid)}"
      end
    end
    
    module ClassMethods
      def find_by_url(url)
        #TODO should check whether given url is really for given class
        self.find(url.scan(/\d+$/)[0].to_i)
      end
    end
  end
end